#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main()
{
	int year = 0, month = 0;
	while (scanf("%d %d", &year, &month) != EOF)
	{
		int days = 0;
		if ((0 == year % 4 && year % 100 != 0) || 0 == year % 400)
		{
			switch (month)
			{
			case 1:
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
			case 12: 
				days = 31;
				break;
			case 2:
				days = 29;
				break;
			case 4:
			case 6:
			case 9:
			case 11: 
				days = 30;
				break;
			}
		}
		else
		{
			switch (month)
			{
			case 1:
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
			case 12:
				days = 31;
				break;
			case 2:
				days = 28;
				break;
			case 4:
			case 6:
			case 9:
			case 11:
				days = 30;
				break;
			}
		}
		printf("%d\n", days);
	}
	return 0;
}
